<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
	<title>Dynatree - Example</title>

	<script src="../jquery/jquery.js" type="text/javascript"></script>
	<script src="../jquery/jquery-ui.custom.js" type="text/javascript"></script>
	<script src="../jquery/jquery.cookie.js" type="text/javascript"></script>

	<link href="../src/skin/ui.dynatree.css" rel="stylesheet" type="text/css">
	<script src="../src/jquery.dynatree.js" type="text/javascript"></script>

	<!-- Start_Exclude: This block is not part of the sample code -->
	<link href="prettify.css" rel="stylesheet">
	<script src="prettify.js" type="text/javascript"></script>
	<link href="sample.css" rel="stylesheet" type="text/css">
	<script src="sample.js" type="text/javascript"></script>
	<!-- End_Exclude -->

<style type="text/css">
  ul.dynatree-container {
	overflow: scroll;
	position: relative;
	width: 200px;
	height: 250px;
  };
</style>

<script type="text/javascript"><!--
$(function(){
	// --- Initialize first Dynatree -------------------------------------------
	$("#tree").dynatree({
		initAjax: {
			url: "sample-data3.json"
		},
		onLazyRead: function(node){
			// Mockup a slow reqeuest ...
			node.appendAjax({
				url: "sample-data2.json",
				debugLazyDelay: 750 // don't do this in production code
			});
		},
		dnd: {
			onDragStart: function(node) {
				/** This function MUST be defined to enable dragging for the tree.
				 *  Return false to cancel dragging of node.
				 */
				logMsg("tree.onDragStart(%o)", node);
				return true;
			},
			onDragStop: function(node) {
				// This function is optional.
				logMsg("tree.onDragStop(%o)", node);
			},
			autoExpandMS: 1000,
			preventVoidMoves: true, // Prevent dropping nodes 'before self', etc.
			onDragEnter: function(node, sourceNode) {
				/** sourceNode may be null for non-dynatree droppables.
				 *  Return false to disallow dropping on node. In this case
				 *  onDragOver and onDragLeave are not called.
				 *  Return 'over', 'before, or 'after' to force a hitMode.
				 *  Return ['before', 'after'] to restrict available hitModes.
				 *  Any other return value will calc the hitMode from the cursor position.
				 */
				logMsg("tree.onDragEnter(%o, %o)", node, sourceNode);
				return true;
			},
			onDragOver: function(node, sourceNode, hitMode) {
				/** Return false to disallow dropping this node.
				 *
				 */
				logMsg("tree.onDragOver(%o, %o, %o)", node, sourceNode, hitMode);
				// Prevent dropping a parent below it's own child
				if(node.isDescendantOf(sourceNode)){
					return false;
				}
				// Prohibit creating childs in non-folders (only sorting allowed)
				if( !node.data.isFolder && hitMode === "over" ){
					return "after";
				}
			},
			onDrop: function(node, sourceNode, hitMode, ui, draggable) {
				/** This function MUST be defined to enable dropping of items on
				 * the tree.
				 */
				logMsg("tree.onDrop(%o, %o, %s)", node, sourceNode, hitMode);
				sourceNode.move(node, hitMode);
				// expand the drop target
//				sourceNode.expand(true);
			},
			onDragLeave: function(node, sourceNode) {
				/** Always called if onDragEnter was called.
				 */
				logMsg("tree.onDragLeave(%o, %o)", node, sourceNode);
			}
		}
	});
});
--></script>
</head>

<body class="example">
	<h1>Example: Move nodes using drag-and-drop</h1>
	<p class="description">
		This sample uses Dynatree's built-in drag-and-drop feature to move nodes.<br>
		- autoExpandMS option is used to expand nodes on mouse hover.<br>
		- The container style uses `overflow: scroll` to demonstrate auto-scrolling.<br>
		- When dropped, the node is moved to the target.
	</p>

	<div id="tree"> </div>

	<!-- Start_Exclude: This block is not part of the sample code -->
	<hr>
	<p class="sample-links  no_code">
		<a class="hideInsideFS" href="http://dynatree.googlecode.com">jquery.dynatree.js project home</a>
		<a class="hideOutsideFS" href="#">Link to this page</a>
		<a class="hideInsideFS" href="samples.html">Example Browser</a>
		<a href="#" id="codeExample">View source code</a>
	</p>
	<pre id="sourceCode" class="prettyprint" style="display:none"></pre>
	<!-- End_Exclude -->
</body>
</html>
